using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Web;

namespace AlphaWebsite.Models
{ 
    public class BudgetItemsRepository : IBudgetItemsRepository
    {
        AlphaWebsiteContext context = new AlphaWebsiteContext();

        public IQueryable<BudgetItems> All
        {
            get { return context.BudgetItems; }
        }

        public IQueryable<BudgetItems> AllIncluding(params Expression<Func<BudgetItems, object>>[] includeProperties)
        {
            IQueryable<BudgetItems> query = context.BudgetItems;
            foreach (var includeProperty in includeProperties) {
                query = query.Include(includeProperty);
            }
            return query;
        }

        public BudgetItems Find(System.Guid id)
        {
            return context.BudgetItems.Find(id);
        }

        public void InsertOrUpdate(BudgetItems budgetitems)
        {
            if (budgetitems.BudgetItemsID == default(System.Guid)) {
                // New entity
                budgetitems.BudgetItemsID = Guid.NewGuid();
                context.BudgetItems.Add(budgetitems);
            } else {
                // Existing entity
                context.Entry(budgetitems).State = EntityState.Modified;
            }
        }

        public void Delete(System.Guid id)
        {
            var budgetitems = context.BudgetItems.Find(id);
            context.BudgetItems.Remove(budgetitems);
        }

        public void Save()
        {
            context.SaveChanges();
        }

        public void Dispose() 
        {
            context.Dispose();
        }
    }

    public interface IBudgetItemsRepository : IDisposable
    {
        IQueryable<BudgetItems> All { get; }
        IQueryable<BudgetItems> AllIncluding(params Expression<Func<BudgetItems, object>>[] includeProperties);
        BudgetItems Find(System.Guid id);
        void InsertOrUpdate(BudgetItems budgetitems);
        void Delete(System.Guid id);
        void Save();
    }
}